/******************************************************************************
 cnome: A C++ source "genes" discover. :-)

 See more details at:

   http://www.codeplex.com/cnome

 The original author site is at: http://www.alexandre-barbosa.com/

 Copyright (c) 2008 Alexandre Barbosa.
 Distributed under the MIT License. (See accompanying file LICENSE-MIT.txt 
 or at http://www.codeplex.com/cnome/license)
 ******************************************************************************/

#ifndef DIRECTIVE_RS_H
#define DIRECTIVE_RS_H

#include "directive_base.h"
#include "variables.h"

namespace cnome { namespace directive {

    struct rs_parser_gen;

    template <typename ParserT>
    struct rs
    :   public boost::spirit::classic::unary<ParserT, boost::spirit::classic::parser<rs<ParserT> > >
    {
        typedef rs<ParserT>                     self_t;
		typedef boost::spirit::classic::unary_parser_category           
			                                    parser_category_t;
        typedef rs_parser_gen                   parser_generator_t;
        typedef boost::spirit::classic::unary<ParserT, boost::spirit::classic::parser<self_t> > 
			                                    base_t;

        rs(ParserT const& p)
        : base_t(p) {}

        template <typename ScannerT>
        typename boost::spirit::classic::parser_result<self_t, ScannerT>::type
        parse(ScannerT const& scan) const
        {
            typedef typename boost::spirit::classic::parser_result<self_t, ScannerT>::type result_t;
            return impl::drt_parser_parse<result_t>
                (*this, scan, scan);
        }

        const char* MyName() const { return "rs"; }

        template <typename ScannerT>
        inline void
        deriv_action_before_parse(
            ScannerT const& scan) const
        {
            var::l_scope.push_back(var::scope);
			wasScopeAbsolut = var::isScopeAbsolut;
        }

        template <typename ScannerT>
        inline void
        deriv_action_after_parse(
            ScannerT const& scan) const
        {
            var::scope = var::l_scope.back();
            var::l_scope.pop_back();
			var::isScopeAbsolut = wasScopeAbsolut;
        }

	private:
		mutable bool wasScopeAbsolut;

    };

    //////////////////////////////////
    const drt_parser_gen<rs> remain_scope_d = drt_parser_gen<rs>();

}} // namespace cnome { namespace directive {

#endif  // DIRECTIVE_RS_H
